﻿ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using Microsoft.Win32;
using Pay_My_Interface.Entity.Product;
using Pay_My_Client.LocalEntity;



namespace Pay_My_Client.Interface.StockGestion
{
    /// <summary>
    /// Logique d'interaction pour Window1.xaml
    /// </summary>
    public partial class AjoutProduitWindow : Window
    {

        IProduct produit;

        public AjoutProduitWindow()
        {
            InitializeComponent();

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openPictureDialog1 = new OpenFileDialog();

            openPictureDialog1.Title = "Choisir une image";
            openPictureDialog1.Filter = "jpeg files (*.jpeg)|*.jpeg| png files (*.png) |*.png| jpg files (*.jpg) |*.jpg| gif files (*.gif) |*.gif";
            openPictureDialog1.CheckFileExists = true;
            openPictureDialog1.CheckPathExists = true;

            Nullable<bool> ret;
            ret = openPictureDialog1.ShowDialog(this);
            if (ret == true)
            {
                if ((myStream = openPictureDialog1.OpenFile()) != null)
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(myStream);
                    // utilisateur.photo = img;
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
                    IntPtr hBitmap = bmp.GetHbitmap();
                    System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    image1.Source = WpfBitmap;
                }
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string erreur = null;

            if (this.Name.Text == "")
                erreur = "Le champ Nom doit être rempli";
           // else if (this.Price.Text == "")
             //   erreur = "Le champ Prix doit être rempli";
            else if (this.CodeBar.Text == "")
                erreur = "Le champ Code Bar doit être rempli";
            else if (erreur != null)
                MessageBox.Show(erreur, "Erreur...", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
            else
            {
                produit.Name = this.Name.Text;
                // produit.Price = this.Price.ReadLocalValue;
                // produit.StaffPrice = this.PriceMember.ReadLocalValue;


            }
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {

        }
    }

}
